package cn.bxshey.general.ThreadPool;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @作者：不想说话而已
 * @Date：2024/1/22 17:38
 *
 * 公共全局异步任务的线程池配置
 */
@Configuration
public class ThreadPoolConfig implements AsyncConfigurer {

    @Bean
    public ThreadPoolTaskExecutor baseThreadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        int size = Runtime.getRuntime().availableProcessors();
        executor.setCorePoolSize(size);
        executor.setMaxPoolSize(size + 2);
        executor.setQueueCapacity(100);
        return executor;
    }
}
